#ifndef XM_EPOLLPOLLER_HH
#define XM_EPOLLPOLLER_HH

#include <vector>

#ifdef __linux__
#include <sys/epoll.h>
#endif // os deps

#include "XM_Poller.hh"
#include "XM_Timestamp.hh"

XM_NAMESPACE_BEGIN

struct Channel;

#define EV_INIT_LIST_SIZE 16

struct EpollPoller : public Poller
{
    EpollPoller(EvLoop* lop);
    ~EpollPoller() override; // from virtual deinit 

    XM_Timestamp poll(int timeoutMs, ChannelList* activeChannels) override;
    void updateChannel(Channel* channel) override;
    void removeChannel(Channel* channel) override;

private:
    static const int INIT_EVENT_LIST_SIZE = EV_INIT_LIST_SIZE;

    void fillActiveChannels(int numEvents, ChannelList* activeChannels) const;
    void update(int operation, Channel* channel);

    using EventList = std::vector<epoll_event>;

    int epollfd__;
    EventList events__;
};

XM_NAMESPACE_END

#endif // header file protect